<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="单据编号" prop="documentNumber">
        <el-input
          v-model="queryParams.documentNumber"
          placeholder="请输入单据编号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用工日期" prop="predictTime">
        <el-date-picker
          v-model="queryParams.predictTime"
          size="mini"
          style="width: 200px"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="单据状态" prop="taskNode">
        <el-select v-model="queryParams.taskNode" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['job:qualityPredict:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getQualityPredictList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="qualityPredictList" >
      <el-table-column type="index" width="60" align="center"/>
      <el-table-column label="质量预测id" v-if="show" prop="qualityPredictId" width="30"/>
      <el-table-column label="单据编号" prop="documentNumber" width="180" align="center"/>
      <el-table-column label="用工日期"  prop="predictTime" width="180" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.predictTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预测24h（万件）" prop="future24PredictNumber" :show-overflow-tooltip="true" width="140" align="center"/>
      <el-table-column label="预测12h（万件)" prop="future12PredictNumber" :show-overflow-tooltip="true" width="140" align="center"/>
      <el-table-column label="省内未发（万件)" prop="provinceNotIssued" width="140" align="center"/>
      <el-table-column label="待卸量（万件)" prop="unloadedNumber" width="120" align="center"/>
      <el-table-column label="状态" prop="taskNode" width="90" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.taskNode == 0">待提交</div>
          <div v-else-if="scope.row.taskNode == 1">已提交</div>
          <div v-else-if="scope.row.taskNode == 2">提交驳回</div>
        </template>
      </el-table-column>

      <el-table-column label="提交时间"  prop="submitTime" width="180" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center"  class-name="small-padding" width="120" fixed="right">
        <template slot-scope="scope" v-if="scope.row.userId !== 1">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleView(scope.row)" v-hasPermi="['job:qualityPredict:detail']">详情</el-button>
          <el-button v-if="scope.row.taskNode !== 1" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['job:qualityPredict:edit']">修改</el-button>
          <el-button v-if="scope.row.taskNode !== 1" size="mini" type="text" icon="el-icon-edit" @click="handleAudit(scope.row)" v-hasPermi="['job:qualityPredict:check']">提交</el-button>
          <el-button v-if="scope.row.taskNode < 2" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['job:qualityPredict:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getQualityPredictList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核结果">
                <el-radio-group v-model="form.taskNode">
                  <el-radio :label="1">通过</el-radio>
                  <el-radio :label="2">不通过</el-radio>
                </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="备注">-->
<!--              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getQualityPredictList , deleteQualityPredict , auditQualityPredict } from "@/api/job/qualityPredict/qualityPredict";
export default {
  name: "attendanceGroup",
  created() {
    this.getQualityPredictList();
  },
  data() {
    return {
      //隐藏id列
      show:false,
      //signUpLoading:true,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      qualityPredictList: [],
      options: [
        { value: '0', label: '待提交' },
        { value: '1', label: '已提交' },
        { value: '2', label: '提交驳回' }
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      signUp:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        documentNumber:undefined,
        submitTime:undefined,
        taskNode:undefined
      },
      // 表单参数
      form: {
        qualityPredictId:undefined,
        //remark:undefined,
        taskNode:undefined,
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },

  methods: {
    /** 获取用工需求列表 */
    getQualityPredictList() {
      this.loading = true;
      getQualityPredictList(this.queryParams).then(
        response => {
          this.qualityPredictList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    handleAdd() {
      this.$router.push({path:"/operationManagement/predict/qualityPredictAdd"});
    },
    handleView(row) {
      this.$router.push({path:"/operationManagement/predict/qualityPredictDetail",query:{qualityPredictId:row.qualityPredictId}});
    },
    handleUpdate(row){
      this.$router.push({path:"/operationManagement/predict/qualityPredictUpdate",query:{qualityPredictId:row.qualityPredictId}});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const qualityPredictId = row.qualityPredictId || this.ids;
      this.$confirm('是否确认删除的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteQualityPredict(qualityPredictId);
        }).then(() => {
          this.getQualityPredictList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /**审核按钮操作*/
    handleAudit(row){
      this.form.qualityPredictId = row.qualityPredictId;
      this.open = true;
      this.title = "审核";
    },
    // 表单重置
    reset() {
      this.form = {
        documentNumber:undefined,
        submitTime:undefined,
        taskNode:undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getQualityPredictList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    submitForm(){
      auditQualityPredict(this.form).then(es=>{
        this.msgSuccess(es.msg);
        this.open = false;
        this.getQualityPredictList()
      })
    .catch(()=>{
      this.msgError("审核失败");
    })},
    cancel(){
      this.open = false;
      this.form.qualityPredictId=undefined;
    },
  }
};
</script>
